<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>初始化 Initializers - Keras 中文文档</title>
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
  
  <script>
    // Current page data
    var mkdocs_page_name = "\u521d\u59cb\u5316 Initializers";
    var mkdocs_page_input_path = "initializers.md";
    var mkdocs_page_url = "/zh/initializers/";
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
  <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-61785484-1', 'keras.io');
      ga('send', 'pageview');
  </script>
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> Keras 中文文档</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
	<ul class="current">
	  
          
            <li class="toctree-l1">
		
    <a class="" href="..">主页</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../why-use-keras/">为什么选择 Keras?</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">快速开始</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../getting-started/sequential-model-guide/">Sequential 顺序模型指引</a>
                </li>
                <li class="">
                    
    <a class="" href="../getting-started/functional-api-guide/">函数式 API 指引</a>
                </li>
                <li class="">
                    
    <a class="" href="../getting-started/faq/">FAQ 常见问题解答</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">模型</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../models/about-keras-models/">关于 Keras 模型</a>
                </li>
                <li class="">
                    
    <a class="" href="../models/sequential/">Sequential 顺序模型 API</a>
                </li>
                <li class="">
                    
    <a class="" href="../models/model/">函数式 API</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Layers</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../layers/about-keras-layers/">关于 Keras 网络层</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/core/">核心网络层</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/convolutional/">卷积层 Convolutional</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/pooling/">池化层 Pooling</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/local/">局部连接层 Locally-connected</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/recurrent/">循环层 Recurrent</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/embeddings/">嵌入层 Embedding</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/merge/">融合层 Merge</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/advanced-activations/">高级激活层 Advanced Activations</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/normalization/">标准化层 Normalization</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/noise/">噪声层 Noise</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/wrappers/">层封装器 wrappers</a>
                </li>
                <li class="">
                    
    <a class="" href="../layers/writing-your-own-keras-layers/">编写你自己的层</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">数据预处理</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../preprocessing/sequence/">序列预处理</a>
                </li>
                <li class="">
                    
    <a class="" href="../preprocessing/text/">文本预处理</a>
                </li>
                <li class="">
                    
    <a class="" href="../preprocessing/image/">图像预处理</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../losses/">损失函数 Losses</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../metrics/">评估标准 Metrics</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../optimizers/">优化器 Optimizers</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../activations/">激活函数 Activations</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../callbacks/">回调函数 Callbacks</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../datasets/">常用数据集 Datasets</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../applications/">应用 Applications</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../backend/">后端 Backend</a>
	    </li>
          
            <li class="toctree-l1 current">
		
    <a class="current" href="./">初始化 Initializers</a>
    <ul class="subnav">
            
    <li class="toctree-l2"><a href="#_1">初始化器的用法</a></li>
    

    <li class="toctree-l2"><a href="#_2">可用的初始化器</a></li>
    
        <ul>
        
            <li><a class="toctree-l3" href="#initializer">Initializer</a></li>
        
            <li><a class="toctree-l3" href="#zeros">Zeros</a></li>
        
            <li><a class="toctree-l3" href="#ones">Ones</a></li>
        
            <li><a class="toctree-l3" href="#constant">Constant</a></li>
        
            <li><a class="toctree-l3" href="#randomnormal">RandomNormal</a></li>
        
            <li><a class="toctree-l3" href="#randomuniform">RandomUniform</a></li>
        
            <li><a class="toctree-l3" href="#truncatednormal">TruncatedNormal</a></li>
        
            <li><a class="toctree-l3" href="#variancescaling">VarianceScaling</a></li>
        
            <li><a class="toctree-l3" href="#orthogonal">Orthogonal</a></li>
        
            <li><a class="toctree-l3" href="#identity">Identity</a></li>
        
            <li><a class="toctree-l3" href="#lecun_uniform">lecun_uniform</a></li>
        
            <li><a class="toctree-l3" href="#glorot_normal">glorot_normal</a></li>
        
            <li><a class="toctree-l3" href="#glorot_uniform">glorot_uniform</a></li>
        
            <li><a class="toctree-l3" href="#he_normal">he_normal</a></li>
        
            <li><a class="toctree-l3" href="#lecun_normal">lecun_normal</a></li>
        
            <li><a class="toctree-l3" href="#he_uniform">he_uniform</a></li>
        
        </ul>
    

    <li class="toctree-l2"><a href="#_3">使用自定义初始化器</a></li>
    

    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../regularizers/">正则化 Regularizers</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../constraints/">约束 Constraints</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../visualization/">可视化 Visualization</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../scikit-learn-api/">Scikit-learn API</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../utils/">工具</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../contributing/">贡献</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">经典样例</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../examples/addition_rnn/">Addition RNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/babi_rnn/">Baby RNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/babi_memnn/">Baby MemNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/cifar10_cnn/">CIFAR-10 CNN</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/cifar10_cnn_capsule/">CIFAR-10 CNN-Capsule</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/cifar10_cnn_tfaugment2d/">CIFAR-10 CNN with augmentation (TF)</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/cifar10_resnet/">CIFAR-10 ResNet</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/conv_filter_visualization/">Convolution filter visualization</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/image_ocr/">Image OCR</a>
                </li>
                <li class="">
                    
    <a class="" href="../examples/imdb_bidirectional_lstm/">Bidirectional LSTM</a>
                </li>
    </ul>
	    </li>
          
        </ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">Keras 中文文档</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
    
    <li>初始化 Initializers</li>
    <li class="wy-breadcrumbs-aside">
      
        <a href="https://github.com/keras-team/keras-docs-zh/edit/master/docs/initializers.md"
          class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h2 id="_1">初始化器的用法</h2>
<p>初始化定义了设置 Keras 各层权重随机初始值的方法。</p>
<p>用来将初始化器传入 Keras 层的参数名取决于具体的层。通常关键字为 <code>kernel_initializer</code> 和 <code>bias_initializer</code>:</p>
<pre><code class="python">model.add(Dense(64,
                kernel_initializer='random_uniform',
                bias_initializer='zeros'))
</code></pre>

<h2 id="_2">可用的初始化器</h2>
<p>下面这些是可用的内置初始化器，是 <code>keras.initializers</code> 模块的一部分: </p>
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L14">[source]</a></span></p>
<h3 id="initializer">Initializer</h3>
<pre><code class="python">keras.initializers.Initializer()
</code></pre>

<p>初始化器基类：所有初始化器继承这个类。</p>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L33">[source]</a></span></p>
<h3 id="zeros">Zeros</h3>
<pre><code class="python">keras.initializers.Zeros()
</code></pre>

<p>将张量初始值设为 0 的初始化器。</p>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L41">[source]</a></span></p>
<h3 id="ones">Ones</h3>
<pre><code class="python">keras.initializers.Ones()
</code></pre>

<p>将张量初始值设为 1 的初始化器。</p>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L49">[source]</a></span></p>
<h3 id="constant">Constant</h3>
<pre><code class="python">keras.initializers.Constant(value=0)
</code></pre>

<p>将张量初始值设为一个常数的初始化器。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>value</strong>: 浮点数，生成的张量的值。</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L66">[source]</a></span></p>
<h3 id="randomnormal">RandomNormal</h3>
<pre><code class="python">keras.initializers.RandomNormal(mean=0.0, stddev=0.05, seed=None)
</code></pre>

<p>按照正态分布生成随机张量的初始化器。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>mean</strong>: 一个 Python 标量或者一个标量张量。要生成的随机值的平均数。</li>
<li><strong>stddev</strong>: 一个 Python 标量或者一个标量张量。要生成的随机值的标准差。</li>
<li><strong>seed</strong>: 一个 Python 整数。用于设置随机数种子。</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L94">[source]</a></span></p>
<h3 id="randomuniform">RandomUniform</h3>
<pre><code class="python">keras.initializers.RandomUniform(minval=-0.05, maxval=0.05, seed=None)
</code></pre>

<p>按照均匀分布生成随机张量的初始化器。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>minval</strong>: 一个 Python 标量或者一个标量张量。要生成的随机值的范围下限。</li>
<li><strong>maxval</strong>: 一个 Python 标量或者一个标量张量。要生成的随机值的范围下限。默认为浮点类型的 1。</li>
<li><strong>seed</strong>: 一个 Python 整数。用于设置随机数种子。</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L122">[source]</a></span></p>
<h3 id="truncatednormal">TruncatedNormal</h3>
<pre><code class="python">keras.initializers.TruncatedNormal(mean=0.0, stddev=0.05, seed=None)
</code></pre>

<p>按照截尾正态分布生成随机张量的初始化器。</p>
<p>生成的随机值与 <code>RandomNormal</code> 生成的类似，但是在距离平均值两个标准差之外的随机值将被丢弃并重新生成。这是用来生成神经网络权重和滤波器的推荐初始化器。</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>mean</strong>: 一个 Python 标量或者一个标量张量。要生成的随机值的平均数。</li>
<li><strong>stddev</strong>: 一个 Python 标量或者一个标量张量。要生成的随机值的标准差。</li>
<li><strong>seed</strong>: 一个 Python 整数。用于设置随机数种子。</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L155">[source]</a></span></p>
<h3 id="variancescaling">VarianceScaling</h3>
<pre><code class="python">keras.initializers.VarianceScaling(scale=1.0, mode='fan_in', distribution='normal', seed=None)
</code></pre>

<p>初始化器能够根据权值的尺寸调整其规模。</p>
<p>使用 <code>distribution="normal"</code> 时，样本是从一个以 0 为中心的截断正态分布中抽取的，<code>stddev = sqrt(scale / n)</code>，其中 n 是：</p>
<ul>
<li>权值张量中输入单元的数量，如果 mode = "fan_in"。</li>
<li>输出单元的数量，如果 mode = "fan_out"。</li>
<li>输入和输出单位数量的平均数，如果 mode = "fan_avg"。</li>
</ul>
<p>使用 <code>distribution="uniform"</code> 时，样本是从 [-limit，limit] 内的均匀分布中抽取的，其中 <code>limit = sqrt(3 * scale / n)</code>。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>scale</strong>: 缩放因子（正浮点数）。</li>
<li><strong>mode</strong>: "fan_in", "fan_out", "fan_avg" 之一。</li>
<li><strong>distribution</strong>: 使用的随机分布。"normal", "uniform" 之一。</li>
<li><strong>seed</strong>: 一个 Python 整数。作为随机发生器的种子。</li>
</ul>
<p><strong>异常</strong></p>
<ul>
<li><strong>ValueError</strong>: 如果 "scale", mode" 或 "distribution" 参数无效。</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L228">[source]</a></span></p>
<h3 id="orthogonal">Orthogonal</h3>
<pre><code class="python">keras.initializers.Orthogonal(gain=1.0, seed=None)
</code></pre>

<p>生成一个随机正交矩阵的初始化器。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>gain</strong>: 适用于正交矩阵的乘法因子。</li>
<li><strong>seed</strong>: 一个 Python 整数。作为随机发生器的种子。</li>
</ul>
<p><strong>参考文献</strong></p>
<p>Saxe et al., http://arxiv.org/abs/1312.6120</p>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/initializers.py#L265">[source]</a></span></p>
<h3 id="identity">Identity</h3>
<pre><code class="python">keras.initializers.Identity(gain=1.0)
</code></pre>

<p>生成单位矩阵的初始化器。</p>
<p>仅用于 2D 方阵。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>gain</strong>: 适用于单位矩阵的乘法因子。</li>
</ul>
<hr />
<h3 id="lecun_uniform">lecun_uniform</h3>
<pre><code class="python">keras.initializers.lecun_uniform(seed=None)
</code></pre>

<p>LeCun 均匀初始化器。</p>
<p>它从 [-limit，limit] 中的均匀分布中抽取样本，
其中 <code>limit</code> 是 <code>sqrt(3 / fan_in)</code>，
<code>fan_in</code> 是权值张量中的输入单位的数量。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>seed</strong>: 一个 Python 整数。作为随机发生器的种子。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个初始化器。</p>
<p><strong>参考文献</strong></p>
<p><a href="http://yann.lecun.com/exdb/publis/pdf/lecun-98b.pdf">LeCun 98, Efficient Backprop</a></p>
<hr />
<h3 id="glorot_normal">glorot_normal</h3>
<pre><code class="python">keras.initializers.glorot_normal(seed=None)
</code></pre>

<p>Glorot 正态分布初始化器，也称为 Xavier 正态分布初始化器。</p>
<p>它从以 0 为中心，标准差为 <code>stddev = sqrt(2 / (fan_in + fan_out))</code> 的截断正态分布中抽取样本，
其中 <code>fan_in</code> 是权值张量中的输入单位的数量，
<code>fan_out</code> 是权值张量中的输出单位的数量。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>seed</strong>: 一个 Python 整数。作为随机发生器的种子。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个初始化器。</p>
<p><strong>参考文献</strong></p>
<p><a href="http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf">Understanding the difficulty of training deep feedforward neural networks</a></p>
<hr />
<h3 id="glorot_uniform">glorot_uniform</h3>
<pre><code class="python">keras.initializers.glorot_uniform(seed=None)
</code></pre>

<p>Glorot 均匀分布初始化器，也称为 Xavier 均匀分布初始化器。</p>
<p>它从 [-limit，limit] 中的均匀分布中抽取样本，
其中 <code>limit</code> 是 <code>sqrt(6 / (fan_in + fan_out))</code>，
<code>fan_in</code> 是权值张量中的输入单位的数量，
<code>fan_out</code> 是权值张量中的输出单位的数量。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>seed</strong>: 一个 Python 整数。作为随机发生器的种子。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个初始化器。</p>
<p><strong>参考文献</strong></p>
<p><a href="http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf">Understanding the difficulty of training deep feedforward neural networks</a></p>
<hr />
<h3 id="he_normal">he_normal</h3>
<pre><code class="python">keras.initializers.he_normal(seed=None)
</code></pre>

<p>He 正态分布初始化器。</p>
<p>它从以 0 为中心，标准差为 <code>stddev = sqrt(2 / fan_in)</code> 的截断正态分布中抽取样本，
其中 <code>fan_in</code> 是权值张量中的输入单位的数量，</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>seed</strong>: 一个 Python 整数。作为随机发生器的种子。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个初始化器。</p>
<p><strong>参考文献</strong></p>
<ul>
<li><a href="http://arxiv.org/abs/1502.01852">Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification</a></li>
</ul>
<hr />
<h3 id="lecun_normal">lecun_normal</h3>
<pre><code class="python">keras.initializers.lecun_normal(seed=None)
</code></pre>

<p>LeCun 正态分布初始化器。</p>
<p>它从以 0 为中心，标准差为 <code>stddev = sqrt(1 / fan_in)</code> 的截断正态分布中抽取样本，
其中 <code>fan_in</code> 是权值张量中的输入单位的数量。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>seed</strong>: 一个 Python 整数。作为随机发生器的种子。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个初始化器。</p>
<p><strong>参考文献</strong></p>
<ul>
<li><a href="https://arxiv.org/abs/1706.02515">Self-Normalizing Neural Networks</a></li>
<li><a href="http://yann.lecun.com/exdb/publis/pdf/lecun-98b.pdf">Efficient Backprop</a></li>
</ul>
<hr />
<h3 id="he_uniform">he_uniform</h3>
<pre><code class="python">keras.initializers.he_uniform(seed=None)
</code></pre>

<p>He 均匀方差缩放初始化器。</p>
<p>它从 [-limit，limit] 中的均匀分布中抽取样本，
其中 <code>limit</code> 是 <code>sqrt(6 / fan_in)</code>，
其中 <code>fan_in</code> 是权值张量中的输入单位的数量。</p>
<p><strong>参数</strong></p>
<ul>
<li><strong>seed</strong>: 一个 Python 整数。作为随机发生器的种子。</li>
</ul>
<p><strong>返回</strong></p>
<p>一个初始化器。</p>
<p><strong>参考文献</strong></p>
<ul>
<li><a href="http://arxiv.org/abs/1502.01852">Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification</a></li>
</ul>
<p>一个初始化器可以作为一个字符串传递（必须匹配上面的一个可用的初始化器），或者作为一个可调用函数传递：</p>
<pre><code class="python">from keras import initializers

model.add(Dense(64, kernel_initializer=initializers.random_normal(stddev=0.01)))

# 同样有效;将使用默认参数。
model.add(Dense(64, kernel_initializer='random_normal'))
</code></pre>

<h2 id="_3">使用自定义初始化器</h2>
<p>如果传递一个自定义的可调用函数，那么它必须使用参数 <code>shape</code>（需要初始化的变量的尺寸）和 <code>dtype</code>（数据类型）：</p>
<pre><code class="python">from keras import backend as K

def my_init(shape, dtype=None):
    return K.random_normal(shape, dtype=dtype)

model.add(Dense(64, kernel_initializer=my_init))
</code></pre>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../regularizers/" class="btn btn-neutral float-right" title="正则化 Regularizers">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../backend/" class="btn btn-neutral" title="后端 Backend"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a href="https://github.com/keras-team/keras-docs-zh/" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../backend/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../regularizers/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>

</body>
</html>
